package com.lancoo.edu.platform.operation.commons.service.api;

import com.alibaba.fastjson.TypeReference;
import com.lancoo.edu.platform.operation.commons.domain.api.code.Code2Info;
import com.lancoo.edu.platform.operation.commons.domain.api.user.UserIdentity;
import com.lancoo.edu.platform.operation.commons.utils.HttpUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 基础平台-【身份】API
 * @author pky
 */
@Service
public class IdentityApiService extends YunBaseApiService {

    /**
     * 获取用户身份信息
     * @param userId 用户ID
     * @param token 令牌
     * @return 身份列表
     */
    public List<UserIdentity> getUserIdentityInfo(String userId, String token) {
        String url = baseUrl + "/UserMgr/PowerMgr/GetIdentityTypeByUserID";
        Map<String, String> paramMap = getParamMap();
        paramMap.put("UserID", userId);
        Map<String, String> header = getHeader(token);
        String resultStr = HttpUtil.sendGet(url, header, paramMap);
        // 设置json 反序列化类型，并提取data数据返回
        return getDataList(resultStr, new TypeReference<Code2Info<List<UserIdentity>>>(){});
    }

    /**
     * 根据身份ID获取身份信息
     * @param token 令牌
     * @param eduId 教育局ID
     * @param identityCode 身份代码
     * @return 身份列表
     */
    public List<UserIdentity> getByIdentityCode(String token, String eduId, String identityCode) {
        String url = baseUrl + "/UserMgr/PowerMgr/GetIdentityTypeByCode";
        Map<String, String> paramMap = getParamMap();
        paramMap.put("EduID", eduId);
        paramMap.put("IdentityCodes", identityCode);
        Map<String, String> header = getHeader(token);
        String resultStr = HttpUtil.sendGet(url, header, paramMap);
        // 设置json 反序列化类型，并提取data数据返回
        return getDataList(resultStr, new TypeReference<Code2Info<List<UserIdentity>>>(){});
    }
}
